package com.itwanyan.m3u8loaderbypublic.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.itwanyan.m3u8loaderbypublic.R;
import com.itwanyan.m3u8loaderbypublic.core.DownloadListener;
import com.itwanyan.m3u8loaderbypublic.core.PulicLoader ;

import java.io.File;

public class MainActivity extends Activity {
    String url = "http://www.gkbbapp.com/Support/Download.aspx?DownloadVideo=2015/11/358_3068181803.mp4&version=831&userId=6&phoneModel=XiaomiMI+3W&type=play";
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = (Button)findViewById(R.id.btn);
    }

    public void pauseAll(View view) {
        PulicLoader.getInstance().pauseAllDownloader();
//        savaData();
    }
    public void startAll(View view) {
//        savaData();
//        PulicLoader.getInstance().startAllDownload();
        Intent intent = new Intent(this,TestLoaderAty.class);
        intent.putExtra("downloadListType",0);
        startActivity(intent);
    }

    private static final String TAG = "MainActivity";

    public void saveData(View view) {
        for (int videoId = 7671; videoId < 7680; videoId++) {
//            int videoId = 7671;
            String urltest = "http://video5.gkbbapp.com/UpLoad/M3U8Media/2016/07/" + videoId + "/" + videoId + ".m3u8";
            final PulicLoader.Downloader downloader = PulicLoader.with(getApplicationContext())
                    .withUrl(String.valueOf(videoId)).filePath(String.valueOf(videoId)).threadCount(3).refreshTime(1000).setDownloadListener(new DownloadListener() {

                        @Override
                        public void onStart() {
                            Log.e(TAG, "onStart: " );
                        }

                        @Override
                        public void onSuccess(File file) {

//                        progressBar.setProgress(100);
//                        btn.setText("下载完毕");
//                        deleteBtn.setEnabled(true);
                            Log.e(TAG, "onSuccess: " );


                        }


                        @Override
                        public void onProgress(long downloadSize, float progress) {

                            int progressInt = (int) (progress * 100);
//                        progressBar.setProgress(progressInt);
//                    btn.setText(String.valueOf(progressInt)+"%");
                            Log.e(TAG, "onProgress: "+progress );
                            Log.e(TAG, "downloadSize: "+downloadSize );
                        }

                        @Override
                        public void onPause() {

//                        btn.setText("继续下载");
//                        deleteBtn.setEnabled(true);
                            Log.e(TAG, "onPause: " );

                        }

                        @Override
                        public void onFail() {
//                        btn.setText("下载失败");
//                        deleteBtn.setEnabled(true);
                            Log.e(TAG, "onFail: " );

                        }

                        @Override
                        public void onDelete(boolean delete) {
//                        btn.setText("下载");
//                        progressBar.setProgress(0);
//                        deleteBtn.setEnabled(true);
                            Log.e(TAG, "onDelete: " );


                        }
                    });
            downloader.download();
        }
//        String videoId = "358";
    }
}
